# -*- coding:utf-8 -*-
from __future__ import print_function
import json, sys
from imp import reload

from workflow import Workflow, web

reload(sys)  # Python2.5 初始化后会删除 sys.setdefaultencoding 这个方法，我们需要重新载入
sys.setdefaultencoding('utf-8')


def main(todoList):
    url = 'http://www.anzhen.tech:8080/getTodo?uId=1'
    r = web.get(url=url)
    r.raise_for_status()
    response = json.loads(r.text)
    data_ = response['data']
    if response['status'] == 'SUCCESS':
        print(data_)
    else:
        print(response['message'])
    for index in range(0, len(data_)):
        todo = data_[index]
        if 'UNDO' == todo['tdStatus']:
            todoList.add_item(title=todo['tdContent'], subtitle=todo['tdContent'], icon='images/UNDO.png',valid=True)
        else:
            todoList.add_item(title=todo['tdContent'], subtitle=todo['tdContent'], icon='images/DONE.png',valid=True)
    todoList.send_feedback()

if __name__ == '__main__':
    wf = Workflow()
    sys.exit(wf.run(main))
